﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;

namespace Sparrow.CMS.Web
{
    public class InstallHttpHandler:IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            var count = Sparrow.Web.Router.Factory.Proivder.RootRouters().Count();

            if (count == 0)
            {
                var router = new Sparrow.Web.Router.WebRouter()
                {
                    Name ="CMS",
                    Sequence = 1,
                    RoutePath = "1"
                };

                Sparrow.Web.Router.Factory.Proivder.Add(router);

                var content = new Sparrow.CMS.PageContent
                {
                    LayoutName = "~/Layout/CMS.html",
                    WebRouter = router,
                    Culture = Thread.CurrentThread.CurrentCulture.Name

                };

                Sparrow.CMS.Facotry.Provider.AddContent(router, content);
            }
        }

        #endregion
    }
}